import { createReducer, on } from '@ngrx/store';
import { FocusActions } from '../actions/focus-action';
import { ActiveModuleState } from '../modules/active-module';


export const focusFeatureKey = 'focus';

export const initialState: ActiveModuleState = { module: '' };

export const focusReducer = createReducer(
  initialState,
  on(
    FocusActions.focusChange,
    // eslint-disable-next-line @ngrx/on-function-explicit-return-type
    (state: ActiveModuleState, { payload }) =>
      // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
     {
      // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
      const  cloneState = <ActiveModuleState>JSON.parse(JSON.stringify(state));
      cloneState.module = payload.module;
      return { ...cloneState};
     }
  )
);
